package Thread_Synchronized_Lock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Thread_SellTickets {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Tickets t = new Tickets();
		Thread t1 = new Thread(t, "窗口1");
		Thread t2 = new Thread(t, "窗口2");
		Thread t3 = new Thread(t, "窗口3");
		t1.start();
		t2.start();
		t3.start();
	}
}

class Tickets implements Runnable {
	int num = 100;
	Object o = new Object();
	Lock lo=new ReentrantLock();
	public void run() {
		while (true) {
			synchronized (o) {
				if (num > 0) {
					try {
						Thread.sleep(100);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					System.out.println(Thread.currentThread().getName() + "---"
							+ (num--));
				}
			}
		}
	}
}
